#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

const int M = 1e6 + 1, N = 2e3 + 10;

int a[N];
struct node
{
    int num, cnt;
    bool operator< (const node& b) const
    {
        if (cnt != b.cnt) return cnt < b.cnt;
        return num < b.num;
    }
};
set<node> tmp;
set<int> ans;
int cnt[M];

void add(int val)
{
    auto it = tmp.lower_bound({ val, cnt[val] });
    cnt[val]++;
    if (it->num == val)
    {
        tmp.erase(it);
        tmp.insert({ val, cnt[val] });
    }
    else
    {
        tmp.insert({ val, 1 });
    }
}

void del(int val)
{
    auto it = tmp.lower_bound({ val, cnt[val] });
    cnt[val]--;
    tmp.erase(it);
    if (cnt[val] >= 1)
    {
        tmp.insert({ val, cnt[val] });
    }
}

int main()
{
    int n; cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        add(a[i]);
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (i == j) continue;
            del(a[i]);
            add(a[i] + 1);
            del(a[j]);
            add(a[j] - 1);
            ans.insert(tmp.rbegin()->num);
            add(a[i]);
            del(a[i] + 1);
            add(a[j]);
            del(a[j] - 1);
        }
    }
    for (auto it = ans.begin(); it != ans.end(); it++) cout << *it << " ";
    return 0;
}